{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "27079d58-de3c-470c-bd4d-a35ea732f96d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集数据的预测标签为 [0 1 1 0 2 2 2 0 0 2 1 0 2 1 1 0 1 1 0 0 1 1 2 0 2 1 0 0 1 2 1 2 1 2 2 0 1\n",
      " 0 1 2 2 0 1 2 1 2 0 0 0 1]\n",
      "测试集数据的真实标签为 [0 1 1 0 2 1 2 0 0 2 1 0 2 1 1 0 1 1 0 0 1 1 1 0 2 1 0 0 1 2 1 2 1 2 2 0 1\n",
      " 0 1 2 2 0 2 2 1 2 0 0 0 1]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<>:13: SyntaxWarning: 'str' object is not callable; perhaps you missed a comma?\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_10064\\2717015840.py:13: SyntaxWarning: 'str' object is not callable; perhaps you missed a comma?\n",
      "  print('测试集共有%d条数据，其中预测错误数据共有%d条，预测准确率为%.2f'(x_test.shape[0],(pred!=y_test).sum(),accuracy_score(y_test,pred)))\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'str' object is not callable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[6], line 13\u001b[0m\n\u001b[0;32m     11\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m测试集数据的预测标签为\u001b[39m\u001b[38;5;124m'\u001b[39m,pred)\n\u001b[0;32m     12\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m测试集数据的真实标签为\u001b[39m\u001b[38;5;124m'\u001b[39m,y_test)\n\u001b[1;32m---> 13\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m测试集共有\u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m条数据，其中预测错误数据共有\u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m条，预测准确率为\u001b[39m\u001b[38;5;132;01m%.2f\u001b[39;00m\u001b[38;5;124m'\u001b[39m(x_test\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m],(pred\u001b[38;5;241m!=\u001b[39my_test)\u001b[38;5;241m.\u001b[39msum(),accuracy_score(y_test,pred)))\n",
      "\u001b[1;31mTypeError\u001b[0m: 'str' object is not callable"
     ]
    }
   ],
   "source": [
    "from sklearn.datasets import load_iris\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "x,y=load_iris().data,load_iris().target\n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=1,test_size=50)\n",
    "model=GaussianNB()\n",
    "model.fit(x_train,y_train)\n",
    "pred=model.predict(x_test)\n",
    "print('测试集数据的预测标签为',pred)\n",
    "print('测试集数据的真实标签为',y_test)\n",
    "print('测试集共有%d条数据，其中预测错误数据共有%d条，预测准确率为%.2f'(x_test.shape[0],(pred!=y_test).sum(),accuracy_score(y_test,pred)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e4428442-8b96-4f2a-9f92-343371e52b3d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
